import 'package:flutter/material.dart';
import 'package:habit_master/config/theme.dart';
import 'package:habit_master/features/community/community_screen.dart';
import 'package:habit_master/features/habit_creation/habit_creation_screen.dart';
import 'package:habit_master/features/habit_management/habit_management_screen.dart';
import 'package:habit_master/features/home/home_screen.dart';
import 'package:habit_master/features/profile/profile_screen.dart';
import 'package:habit_master/features/statistics/statistics_screen.dart';
import 'package:habit_master/widgets/bottom_nav_bar.dart';

class HabitMasterApp extends StatelessWidget {
  const HabitMasterApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '习惯掌控',
      theme: appTheme,
      home: const MainScreen(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MainScreen extends StatefulWidget {
  const MainScreen({Key? key}) : super(key: key);

  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  int _currentIndex = 0;

  final List<Widget> _screens = [
    const HomeScreen(),
    const HabitManagementScreen(),
    const StatisticsScreen(),
    const CommunityScreen(),
    const ProfileScreen(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _screens,
      ),
      bottomNavigationBar: CustomBottomNavBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => const HabitCreationScreen(),
            ),
          );
        },
        child: const Icon(Icons.add),
        backgroundColor: Theme.of(context).primaryColor,
      ),
    );
  }
}
